
namespace SB2.Core;
public class UserRepository : AppSugarRepository<User>
{
    public UserRepository(ISqlSugarClient context) : base(context)
    {

    }
    public async Task<PagedResponse> GetPageListAsync(PagedRequest page)
    {
        return await GetPageListAsync<UserDto>(page);
    }
    public async Task<bool> InsertAsync(UserCreateDto dto)
    {
        var user = dto.Adapt<User>();
        // 重复验证

        // 初始化密码
        user.New().SetPwd("123456");
        return await InsertAsync(user);
    }
    public async Task<bool> UpdateAsync(UserUpdateDto dto)
    {

        var user = await GetByIdAsync(dto.UserID);
        if (user == null)
            throw Oops.Oh("账号不存在！");
        if (!string.IsNullOrEmpty(dto.Pwd))
            user.SetPwd(dto.Pwd);
        if (dto.AdminStatus != null)
            user.AdminStatus = dto.AdminStatus.Value;
        return await UpdateAsync(new User { UserID = user.UserID, AdminStatus = user.AdminStatus, Pwd = user.Pwd });
    }
}